home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 03 - 1987 / 03.04 Apr 87 / zbasic scroll / SCROLL.BAS < prev   
Encoding:
BASIC Source File  |  1987-02-17  |  3.3 KB  |  96 lines  |  [TEXT/ZBAS]

  1. REM *************** Text Window Scroll Bar(s) Example ********************
  2. REM *** ZBasic 3.05 or Greater (public domain)  1/87 A.G ZEDCOR, INC.  ***
  3. REM *** with modifications & explainations 2/87 by D. Kelly  MacTutor™ ***
  4. REM **********************************************************************
  5. WINDOW OFF
  6. COORDINATE WINDOW
  7. WIDTH -2
  8. False = 0 : True = NOT False
  9. X=MEM(-1) :REM *** Disable Line Wrap ***
  10. WINDOW 1,"Untitled",(50,50)-(450,255),9  : REM ** Initial Window Size **
  11. TEXT 4,9
  12. MENU 1,0,1,"File"
  13. MENU 1,1,1,"Open"
  14. MENU 1,2,0,"-"
  15. MENU 1,3,1,"Quit"
  16. MENU 2,0,1,"Scroll Type"
  17. MENU 2,1,1,"Normal Scroll"
  18. MENU 2,2,1,"Soft Scroll"
  19. DIM Ascent,Descent,WidMax,Leading
  20. CALL GETFONTINFO(Ascent)
  21. Height=Ascent+Descent+Leading :REM * Font Size *
  22. GOSUB "Openfile"
  23. OV=False 
  24. OH=True 
  25. Softscroll=False : REM **** Softscroll = Soft-Scroll Flag ****
  26. SCROLL BUTTON 1,OV,OV,TL-1,TL/10,,1 
  27. SCROLL BUTTON 2,OH,OH,255,10,,2
  28. ON DIALOG GOSUB "Dialog"
  29. ON MENU GOSUB "MenuEvent"
  30. WINDOW#1,A$ : REM *** File name to Title ***
  31. DIALOG ON
  32. MENU ON
  33. BREAK ON : REM **> Var 'Softscroll' 0=Normal Scroll 1=Soft Scroll **
  34. "Loop"    : GOTO "Loop" : REM *** Main Event Trapping Loop ***
  35. DIALOG OFF: BREAK OFF :MENU OFF: REM *** Turn OFF dialogs for rest of PGM ***
  36. "MenuEvent"
  37. Menunumber = MENU(0)
  38. Menuitem = MENU(1)
  39. LONG IF Menunumber = 1 
  40. IF Menuitem = 1 THEN GOSUB "Openfile"
  41. IF Menuitem = 3 THEN STOP
  42. END IF
  43. IF Menuitem = 1 THEN Softscroll = 0 ELSE Softscroll = 1
  44. MENU
  45. RETURN
  46. "Dialog"  : D=DIALOG(0) : REM **** Dialog Events come here.. ****
  47. ON D GOTO "Button","X","ACTIVE","GoAway","Update","X","X","Zoom","Zoom"
  48. "ACTIVE"
  49. WINDOW #DIALOG(D) 
  50. RETURN : REM ** Activate this Window **
  51. "Button"
  52. IF DIALOG(D)=1 THEN Buttonvalue=BUTTON(1)  ELSE "Side"
  53. X=OV-Buttonvalue
  54. IF ABS(X) > SL THEN OV=Buttonvalue : CLS : GOTO "Update"
  55. IF X>0 THEN DV=Height :DL=-1 :Leading=0 :P=Ascent ELSE DV=-Height :DL=+1 :Leading=SL+1 :P=(SL-1)*Height+Ascent
  56. WHILE OV<>Buttonvalue
  57. IF Softscroll THEN DV=SGN(DV) : II=1 ELSE II=Height
  58. FOR II=II TO Height : REM **** If THIS LINE if Soft-Scroll Not used *****
  59. SCROLL (0,0)-(W6,W7),,DV : REM ***** SCROLL 1 line or 1 Pixel  *****
  60. PRINT %(-BUTTON(2)*WidMax,P+(DV*(II-Height)));INDEX$(OV-1+Leading);
  61. NEXT 
  62. OV=OV+DL : REM **** Remove NEXT if soft-scroll not used ***
  63. WEND   : RETURN
  64. "Zoom" 
  65. CLS : RETURN : REM ***** ERASE IF ZOOM-IN OR ZOOM OUT *****
  66. "Side" 
  67. SCROLL(0,0)-(W6,W7),(OH-BUTTON(2))*WidMax,0:OH=BUTTON(2)
  68. "Update"
  69. W6=WINDOW(6)-1 : W7=WINDOW(7)-1 : SL=W7/Height
  70. FOR II= OV TO OV+SL-1 : REM ******* Re-Draw Full Screen *******
  71. PRINT %(-BUTTON(2)*WidMax,(II-OV)*Height+Ascent);INDEX$(II);
  72. NEXT
  73. COLOR 0 :BOX FILL 0,SL*Height TO W6,W7 :COLOR -1 :REM *Erase Bottom*
  74. "X" 
  75. RETURN : REM  **** Just RETURN routine ****
  76. "GoAway"
  77. STOP
  78. "Openfile" : A$=FILES$(1,"TEXT",,V%) 
  79. IF A$="" THEN BEEP : STOP ELSE CLS
  80. OPEN "I",#1,A$,1,V% 
  81. CLEAR LOF(1)+32
  82. TL=0 
  83. IF MEM=0 THEN STOP
  84. WHILE NOT EOF(1) : REM ******> Read TEXT file into INDEX$ array <*******
  85. LINEINPUT#1,W$
  86. INDEX$(TL)=W$ 
  87. TL=TL+1 : REM FILL INDEX$ FROM FILE
  88. WEND 
  89. CLOSE 
  90. RETURN
  91. REM ***********************************************************************
  92. REM ** Some Possible Changes:                                            **
  93. REM ** Line 210 Change 'ABS(X) > SL' to 'ABS(X) > 1' Single Line Soft    **
  94. REM ** Add 'CLEAR 0' to Erase INDEX$ Array When Text Window Closed.      **
  95. REM ***********************************************************************
  96.